package com.da.javatest.interview.session2;

import java.util.concurrent.TimeUnit;

/**
 * @author chenlida
 * @date 2020/3/28 19:05
 * @description 可见性测试
 */
public class Test01Visibility {
    public static void main(String[] args) {
        MyDataClass myData = new MyDataClass();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t come in");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            myData.addTo60();
            System.out.println(Thread.currentThread().getName() + "\t update num to 60");
        }, "AAA").start();

        while (myData.num == 0) {
            // 循环直到num不等于0为止
        }
        System.out.println(Thread.currentThread().getName() + "\t end");
    }
}
